﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Arch.Data;
using Arch.Samples.Data.Contracts;
using Arch.Samples.Model;
using Arch.Samples.Mvc.Infrastructure;
using Microsoft.Practices.Unity;

namespace Arch.Samples.Mvc.Controllers
{
    public class TodoController : CrudControllerBase<Todo>
    {
        [Dependency]
        public ITodoRepository TodoRepository { get; set; }

        protected override void LoadDependencies(Todo entity)
        {
            ViewData["GlobalCategoryId"] = SelectList(Repository.Find<GlobalCategory>(), selectedValue:entity.GlobalCategoryId, emptyValueField: "");
            ViewData["SubCategoryId"] = SelectList(Repository.Find<SubCategory>(), selectedValue: entity.SubCategoryId, emptyValueField: "");
        }

        public ActionResult Search(string query)
        {
            return View("Index", TodoRepository.Search(query));
        }

        [Authorize]
        public override ActionResult Create()
        {
            return base.Create();
        }

        [HttpPost, Authorize]
        public override ActionResult Create(FormCollection collection)
        {
            return base.Create(collection);
        }

        [Authorize]
        public override ActionResult Edit(int id)
        {
            return base.Edit(id);
        }

        [HttpPost, Authorize]
        public override ActionResult Edit(int id, FormCollection collection)
        {
            return base.Edit(id, collection);
        }
    }
}
